package com.situ.vivamarket.controller.sys;

import com.situ.vivamarket.model.Admin;
import com.situ.vivamarket.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/vm/sys/admin")
public class AdminController {
    private AdminService adminService;
    @Autowired
    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    @GetMapping("/list")
    public String list() {

        return "sys/admin/list";
    }
    @GetMapping("/add")
    public String add() {
        return "sys/admin/add";
    }
    @GetMapping("/edit")
    public String edit(Integer id, Map<String,Object> map) {
        if (id == null) {
            map.put("error","修改的管理员编号为空");
            return "sys/admin/edit";
        }else{
            Admin admin = adminService.findById(id);
            if(admin == null) {
                map.put("error","修改的管理员为空");
                return "sys/admin/edit";
            }else{
                map.put("admin",admin);
            }
        }
        return "/sys/admin/edit";
    }

}
